const request = require("../../../utils/request");
const image = "https://tdesign.gtimg.com/mobile/demos/example2.png";
const items = new Array(12).fill({ label: "标题文字", image }, 0, 12);

Page({
  offsetTopList: [],
  data: {
    //商品列表
    goodsList: [
      {
        id: 1,
        im: "/static/img/sp.png",
        title: "咖啡机咖啡机1",
        jian: "产品简介产品简介",
        xl: "265",
        pr: "200",
        po: "500",
        url: "/pages/prodetails/prode",
      },
      {
        id: 2,
        im: "/static/img/sp2.png",
        title: "咖啡机咖啡机2",
        jian: "产品简介产品简介",
        xl: "265",
        pr: "200",
        po: "500",
        url: "/pages/prodetails/prode",
      },
      {
        id: 3,
        im: "/static/img/sp3.png",
        title: "咖啡机咖啡机3",
        jian: "产品简介产品简介",
        xl: "265",
        pr: "200",
        po: "500",
        url: "/pages/prodetails/prode",
      },
      {
        id: 4,
        im: "/static/img/sp4.png",
        title: "咖啡机咖啡机4",
        jian: "产品简介产品简介",
        xl: "265",
        pr: "200",
        po: "500",
        url: "/pages/prodetails/prode",
      },
      {
        id: 5,
        im: "/static/img/sp3.png",
        title: "咖啡机咖啡机5",
        jian: "产品简介产品简介",
        xl: "265",
        pr: "200",
        po: "500",
        url: "/pages/prodetails/prode",
      },
      {
        id: 6,
        im: "/static/img/sp4.png",
        title: "咖啡机咖啡机6",
        jian: "产品简介产品简介",
        xl: "265",
        pr: "200",
        po: "500",
        url: "/pages/prodetails/prode",
      },
    ],
    sideBarIndex: 0,
    scrollTop: 0,
    categories: [
      {
        label: "选项一",
        title: "标题一",
        items,
      },
      {
        label: "选项二",
        title: "标题二",
        badgeProps: {},
        items: items.slice(0, 10),
      },
      {
        label: "选项三",
        title: "标题三",
        badgeProps: {},
        items: items.slice(0, 6),
      },
      {
        label: "选项四",
        title: "标题四",
        items: items.slice(0, 8),
      },
      {
        label: "选项五",
        title: "标题五",
        badgeProps: {},
        disabled: true,
        items: [],
      },
    ],
    navbarHeight: 0,
    categories1: "",
    goodslist1:"",
  },
  // 分类菜单列表
  getCategories() {
    const _this = this;
    request.wxRequest(
      "menu/list2",
      function (err, data) {
        // console.log(data.data.list);
        if (err) {
          // 失败；
        } else {
          _this.setData({
            categories1: data.data.list,
          });
        }
      },
      "GET",
      {
        id: 1,
        name: 123,
      }
    );
  },
  // 分类商品列表
  goodslist(){
    const _this = this;
    request.wxRequest(
      "product/list2",
      function (err, data) {
        // console.log(data.data.list);
        if (err) {
          // 失败；
        } else {
          _this.setData({
            goodslist1: data.data.list,
          });
        }
      },
      "POST",
      {
        menuId: 1,
        name: 123,
      }
    );
  },
  onLoad() {
    // 分类菜单列表
    this.getCategories();
    // 分类商品列表
    this.goodslist();
    this.getCustomNavbarHeight();
  },

  getCustomNavbarHeight() {
    const query = wx.createSelectorQuery();
    query.select(".custom-navbar").boundingClientRect();
    query.exec((res) => {
      const { height = 0 } = res[0] || {};
      this.setData({ navbarHeight: height });
    });
  },

  onSideBarChange(e) {
    const { value } = e.detail;

    this.setData({ sideBarIndex: value, scrollTop: 0 });
  },
});
